package com.tcm.controller.backend;

import com.tcm.entity.resp.R;
import com.tcm.service.*;
import com.tcm.utils.AccessTokenUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 所教学生学生管理控制器
 * @author Guqier
 * @version 1.0
 * @date 2023/10/12 10:52
 */
@RestController
@RequestMapping("/pc/manage")
@RequiredArgsConstructor
public class StudentManageController {

    private final GroupService groupService;

    private final CollectService collectService;

    private final NoteService noteService;

    private final ItemStudentService itemStudentService;

    private final BattleService battleService;

    private final StatisticsService statisticsService;

    /**
     * 通过教师账号获取所教班级学生加入的小组列表
     * @param request 请求对象
     * @return 所教班级学生加入的小组列表
     */
    @RequestMapping(value = "/group", method = RequestMethod.GET)
    public R getGroupListByTeacher(HttpServletRequest request) {
        return R.success(groupService.getGroupListByTeacherAccount(AccessTokenUtil.getUserAccount(request), AccessTokenUtil.getUserId(request)));
    }

    /**
     * 获取学习小组详细信息
     * @param groupId 小组ID
     * @param range   查询数据范围
     * @param request 请求对象
     * @return 小组详细信息
     */
    @RequestMapping(value = "/group/detail", method = RequestMethod.GET)
    public R getGroupDetail(@RequestParam Long groupId, @RequestParam String range, HttpServletRequest request) {
        return R.success(groupService.getGroupInfoByTeacherAccount(groupId, range, AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 分页教师获取学生收藏列表
     * @param page     当前页号
     * @param pageSize 页面大小
     * @param account  检索学生账号
     * @param request  请求对象
     * @return 学生收藏列表
     */
    @RequestMapping(value = "/collect", method = RequestMethod.GET)
    public R getCollectListByTeacher(@RequestParam Integer page,
                                     @RequestParam Integer pageSize,
                                     @RequestParam(required = false) String account,
                                     HttpServletRequest request) {
        return R.success(collectService.getCollectListByTeacher(page, pageSize, account, AccessTokenUtil.getUserId(request), AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 分页教师获取学生笔记列表
     * @param page     当前页号
     * @param pageSize 页面大小
     * @param account  检索学生账号
     * @param request  请求对象
     * @return 学生笔记列表
     */
    @RequestMapping(value = "/note", method = RequestMethod.GET)
    public R getNoteListByTeacher(@RequestParam Integer page,
                                  @RequestParam Integer pageSize,
                                  @RequestParam(required = false) String account,
                                  HttpServletRequest request) {
        return R.success(noteService.getNoteListByTeacher(page, pageSize, account, AccessTokenUtil.getUserId(request), AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 获取学生练习记录
     * @param page     当前页号
     * @param pageSize 页面大小
     * @param account  检索学生账号
     * @param request  请求对象
     * @return 学生练习记录
     */
    @RequestMapping(value = "/history", method = RequestMethod.GET)
    public R getHistoryListByTeacher(@RequestParam Integer page,
                                     @RequestParam Integer pageSize,
                                     @RequestParam(required = false) String account,
                                     HttpServletRequest request) {
        return R.success(itemStudentService.getStudentHistoryByTeacher(page, pageSize, account, AccessTokenUtil.getUserId(request), AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 教师分页获取所教学生PK记录
     * @param page 当前页号
     * @param pageSize 页面大小
     * @param account 检索学生账号
     * @param request 请求对象
     * @return PK记录
     */
    @RequestMapping(value = "/battle", method = RequestMethod.GET)
    public R getBattleListByTeacher(@RequestParam Integer page,
                                    @RequestParam Integer pageSize,
                                    @RequestParam(required = false) String account,
                                    HttpServletRequest request){
        return R.success(battleService.getBattleListByTeacher(page, pageSize, account, AccessTokenUtil.getUserId(request), AccessTokenUtil.getUserAccount(request)));
    }

    /**
     * 获取对战详细信息
     * @param battleId 对战记录ID
     * @return 详细信息
     */
    @RequestMapping(value = "/battle/detail", method = RequestMethod.GET)
    public R getBattleDetailByTeacher(@RequestParam Long battleId){
        return R.success(battleService.getBattleDetailByTeacher(battleId));
    }
}
